package cn.net.yto.school.service.impl;

import cn.net.yto.base.dao.pagination.PaginationRequest;
import cn.net.yto.base.dao.pagination.PaginationResponse;
import cn.net.yto.school.dao.entities.TbStudent;
import cn.net.yto.school.dao.repositories.TbStudentRepository;
import cn.net.yto.school.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private TbStudentRepository studentRepository;

    @Override
    public PaginationResponse<TbStudent> findResultsByPagination(PaginationRequest paginationRequest) {
        return this.studentRepository.findResultsByPagination(paginationRequest);
    }

    @Override
    @Transactional
    public void deleteStudentById(Integer id) {
        this.studentRepository.delete(id);
    }

    @Override
    @Transactional
    public void saveStudent(TbStudent student) {
        this.studentRepository.save(student);
    }

    @Override
    public TbStudent findOne(Integer id) {
        return this.studentRepository.findOne(id);
    }

    @Override
    public List<TbStudent> findAll() {
        return this.studentRepository.findAll();
    }

    @Override
    public Long countStus() {
        return this.studentRepository.count();
    }
}
